package com.medical.service.impl;

import com.medical.entity.UserEntity;
import com.medical.entity.vo.PrescriptionVo;
import com.medical.mapper.UserMapper;
import com.medical.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Component
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 用户登录
     *
     * @param userAccount
     * @param userPassword
     * @return
     */
    @Override
    public UserEntity login(String userAccount, String userPassword) {
        return userMapper.findByUserAccountAndUserPassword(userAccount, userPassword);
    }

    /**
     * 用户注册，同时检查用户唯一性
     *
     * @param
     * @return
     */
    @Override
    public boolean register(String userAccount, String userPassword, String userName) {
        UserEntity existingUser = userMapper.findByUserAccount(userAccount);
        if (existingUser != null) {
            return false;
        } else {
            userMapper.insertUser(userAccount, userPassword, userName); // 保存新用户到数据库
            return true; // 注册成功
        }
    }

    /**
     * 查询用户信息
     *
     * @return
     */
    @Override
    public List<UserEntity> selectList() {
        return userMapper.selectList();
    }

    /**
     * 修改用户信息
     *
     * @param userEntity
     * @return
     */
    @Override
    public int update(UserEntity userEntity) {
        return userMapper.update(userEntity);
    }

    /**
     * 修改密码
     * @param userId
     * @param userPassword
     * @return
     */
    @Override
    public int updateById(String userId,String userPassword) {
        return userMapper.updateById(userId,userPassword);
    }
    /**
     * 注销用户
     * @param
     * @return
     */
    @Override
    public boolean delete(String userAccount) {
        return userMapper.delete(userAccount);
    }

    @Override
    public PrescriptionVo selectByIdDetails(String userId) {
        return userMapper.selectByIdDetails(userId);
    }

}
